import os


# 判断文件是否存在
def check_file_exists(filename):
    """
    检查文件是否存在。
    
    :param filename: 文件名（在同一目录下）或文件的相对/绝对路径。
    :return: 如果文件存在返回 True，否则返回 False。
    """
    return os.path.exists(filename)

# 这是测试写入
def test_write_python_script(file_path):
    # 要写入的内容
    content = '''#!/usr/bin/env python3
# 这是自动生成的脚本

def greet(name):
    """打招呼函数"""
    print(f"Hello, {{name}}!")

if __name__ == "__main__":
    greet("World")
'''

    # 写入文件
    with open(file_path, 'w', encoding='utf-8') as f:
        f.write(content)

    print(f"脚本已成功写入到: {file_path}")

# 写入储备函数
def write_head(cutPyFileName):

    content = '''

import doCut

'''

    # 写入文件
    with open(cutPyFileName, 'w', encoding='utf-8') as f:
        f.write(content)

    print(f"\n\n储备函数所在的doCut已作为header成功写入到: {cutPyFileName}\n\n")


# 写入各段剪切时间A, B点
def write_records(atime, btime, rotation, vflip, cutPyFileName, keyWords):
    
    
    content = f'''

doCut.CutIt('{atime}', '{btime}', {rotation}, {vflip}, '{keyWords}')

'''

        

    # 写入文件用w, 而追加则用a
    with open(cutPyFileName, 'a', encoding='utf-8') as f:
        f.write(content)

    print(f"\n\n本条切割时间段 {atime}-{btime} 已成功写入到: {cutPyFileName}\n\n")



# # 示例调用
# if __name__ == "__main__":
#     script_name = "_generated_script.py"
#     write_head(script_name)
#     write_records('1:01:45.583', '1:01:52.506', script_name)
